package org.dromara.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.StreamingChatModel;
import dev.langchain4j.service.AiServices;
import lombok.RequiredArgsConstructor;
import org.dromara.web.controller.ApiController;
import org.dromara.web.mapper.MarketMapper;
import org.dromara.web.service.IChatAssistant;
import org.dromara.web.service.impl.ApiServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.web.client.RestTemplate;
@Configuration
@RequiredArgsConstructor
public class LLMConfig {
    private final ChatModel chatModel;
    private final StreamingChatModel streamingChatModel;
    private final RestTemplate restTemplate;
    private final MarketMapper marketMapper;
    private final ObjectMapper objectMapper;

    @Bean
    public IChatAssistant chatAssistant() {
        return AiServices
            .builder(IChatAssistant.class)
            // 指定模型
            .chatModel(chatModel)
            .streamingChatModel(streamingChatModel)
            // 工具类
//            .tools(new NumberHandler(),new ApiServiceImpl(restTemplate, marketMapper, objectMapper))
            .tools(new ApiController(new ApiServiceImpl(restTemplate, marketMapper, objectMapper)))
            // js工具
//                .tools(new GraalVmJavaScriptExecutionTool())
                .build();
    }


}
